/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.gr.jcash.dmp;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author gelson
 */
@Entity
@Table(name = "categoria", catalog = "jcash", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Categoria.buscarTodos", query = "SELECT c FROM Categoria c WHERE c.usuario = :p0 ORDER BY c.catDescricao"),
    @NamedQuery(name = "Categoria.buscarPorId", query = "SELECT c FROM Categoria c WHERE c.idCat = :p0 AND c.usuario = :p1"),
    @NamedQuery(name = "Categoria.buscarPorCatTipo", query = "SELECT c FROM Categoria c WHERE c.usuario = :p0 and c.catTipo in(:p1) "),
    @NamedQuery(name = "Categoria.buscarPorCatDescricao", query = "SELECT c FROM Categoria c WHERE c.catDescricao = :p0 AND c.usuario = :p1"),
    @NamedQuery(name = "Categoria.count", query = "SELECT COUNT(c.idCat) FROM Categoria c WHERE c.usuario = :p0")})
public class Categoria extends EntidadeBase implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_cat", nullable = false)
    private Long idCat;
    @Basic(optional = false)
    @NotNull
    @Column(name = "cat_tipo")
    @Enumerated(EnumType.STRING)
    private TipoCategoria catTipo;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "cat_descricao", nullable = false, length = 100)
    private String catDescricao;
    @JoinColumn(name = "id_usu", referencedColumnName = "id_usu", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Usuario usuario;

    public Categoria() {
    }

    public Long getIdCat() {
        return idCat;
    }

    public void setIdCat(Long idCat) {
        this.idCat = idCat;
    }

    public TipoCategoria getCatTipo() {
        return catTipo;
    }

    public void setCatTipo(TipoCategoria catTipo) {
        this.catTipo = catTipo;
    }

    public String getCatDescricao() {
        return catDescricao;
    }

    public void setCatDescricao(String catDescricao) {
        this.catDescricao = catDescricao;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCat != null ? idCat.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Categoria)) {
            return false;
        }
        Categoria other = (Categoria) object;
        if ((this.idCat == null && other.idCat != null) || (this.idCat != null && !this.idCat.equals(other.idCat))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return catDescricao;
    }
    
    @Override
    public void setId(Long id) {
        this.idCat = id;
}

    @Override
    public Long getId() {
        return idCat;
    }
    
}
